package com.gitee.feizns.quickstart.ding.talk.api.top.api.v2.department;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiV2DepartmentGetRequest;
import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 获取部门详情（/topapi/v2/department/get）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/obtain-the-department-list-v2">获取部门详情（/topapi/v2/department/get）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/obtain-the-department-list-v2">服务端API 通讯录管理 部门管理 获取部门详情</a>
 * @author feizns
 * @since 2024/6/29
 */
public class Get {

    /**
     * 获取部门详情
     * @param accessToken 访问令牌
     * @param deptId 部门 ID
     * @return {@link OapiV2DepartmentGetResponse.DeptGetResponse }
     */
    @SneakyThrows
    public static OapiV2DepartmentGetResponse.DeptGetResponse execute(String accessToken, Long deptId) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/get");
        OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
        req.setDeptId(deptId);
        req.setLanguage("zh_CN");
        OapiV2DepartmentGetResponse rsp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(rsp).getResult();
    }

}
